package btest;

import java.util.PriorityQueue;
import java.util.Queue;

/**
 * AdorynZhao in Toutiao-UESTC.
 * Source Code Created on 2017/12/7.
 */
public class PriorityQueueTest {

    public static void main(String[] args) {
        Queue<Item> queue = new PriorityQueue<>();

        Item item = new Item(9);
        queue.offer(item);

        for (int i = 2; i < 10; i++) {
            queue.offer(new Item(i * 2));
        }

        queue.remove(item);
        item.value = 3;
        queue.offer(item);

        while (!queue.isEmpty()) {
            System.out.print(queue.poll().value + " ");
        }

        System.out.println();
    }

    public static class Item implements Comparable<Item>{
        public int value = 0;

        public Item(int val) {
            this.value = val;
        }

        @Override
        public int compareTo(Item o) {
            if (this.value > o.value)
                return -1;
            else if (this.value < o.value)
                return 1;

            return 0;
        }
    }
}
